﻿using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using Object = UnityEngine.Object;

namespace COC.DEBUG
{
    //debug conditions and  debug types which display on screen.
    public sealed class CDebug
    {
       
            public static readonly byte AI = 1<<0;//if set,will be enable ai debug information.

            public static readonly byte THREAD_POOL = 1<<1;//enable thread pool.

            public static readonly byte PATH_FINDING = 1<<2; //enable path finding when debug what debug ai path if necessary

            public static readonly byte GRAPH_UPDATED = 1<<3;//show updating graph on scence continuously,if enable.  

            public static readonly byte UI_ACTION = 1<<4;//debug about direct-ui such button,slide,slash screen etc,totally,just relation of non-3d actions.

            public static readonly byte SERVICE = 1<<5; //debug about related service such audio sevice network service etc

            public static readonly int SHADER = 7;//about shader

            public static readonly int MATERIALS = 8;//about materials from 3d module.

            public static readonly int ASSET_DATA = 9;//about persistence such as database,loading preference 

            public static readonly int MOVING = 10;//about ai to move after calculate.

            public static readonly int TEST = 11;//about miscellaneous that used to test .

            public static readonly int ALGORITHM = 12;//about algorithms.

            public static readonly int ALL = 13;//if set,will show all debug infos.

            private static int debugType;

            private static readonly String COLON_SYMBOL = ":";
            private static readonly String LOG_INFO_FLAG = "[INFO]"+COLON_SYMBOL;
            private static readonly String LOG_ERROR_FLAG = "[ERROR]"+COLON_SYMBOL;
            private static readonly String LOG_WARNING_FLAG = "[WARNING]"+COLON_SYMBOL;

           // private static readonly String LOG_PATH = Application.RegisterLogCallback().+"";
            private static readonly String LOG_TXT_NAME = "";
            /// <summary>
            /// debug level:ERROR=1 WARRING=2 INFO=3
            /// </summary>
            public enum Level
            {
                INFO=1,
                WARNING=2,
                ERROR=3,
            }

           /// <summary>
           /// register to show module debug information according debug mode: AI,Pathfinding,Service etc. 
           /// </summary>
            /// <param name="type">if show multiple module information,please inject:mode1 | mode2 |mode3 for example,if you will debug AI and pathfinding module,you need: <see cref="CDebug.AI">AI</see>|<see cref="CDebug.PATH_FINDING">PATH_FINDING</see></param>
            public void registerDebug(int type)
            {
                 debugType=type;
                
            }
            public void save()
            {
                
            }
           
            public static void Log(int type,String message,Object context)
            {
                if (type == ALL) { if (context != null) { UnityEngine.Debug.LogWarning(LOG_WARNING_FLAG + message, context); return; } UnityEngine.Debug.LogWarning(LOG_WARNING_FLAG + message); return; }
                if (type == ALL) { if (context != null) { UnityEngine.Debug.Log(LOG_INFO_FLAG + message, context); return; } UnityEngine.Debug.Log(LOG_INFO_FLAG + message); return; }
                if ((debugType & type) == type) {
                    if (context != null) { UnityEngine.Debug.Log(LOG_INFO_FLAG + message, context); return; } UnityEngine.Debug.Log(LOG_INFO_FLAG + message);
                }
            }
            public static void LogWarning(int type, String message,Object context)
            {
                if (type == ALL) { if (context != null) { UnityEngine.Debug.LogWarning(LOG_WARNING_FLAG + message, context); return; } UnityEngine.Debug.LogWarning(LOG_WARNING_FLAG + message); return; }
                if ((debugType & type) == type) {
                    if (context != null) { UnityEngine.Debug.LogWarning(LOG_WARNING_FLAG + message, context); return; } UnityEngine.Debug.LogWarning(LOG_WARNING_FLAG + message);
                }
            }
            public static void LogError(int type, String message,Object context)
            {
                if (type == ALL) { if (context != null) { UnityEngine.Debug.LogError(LOG_ERROR_FLAG + message, context); return; } UnityEngine.Debug.LogError(LOG_ERROR_FLAG + message); return; }
                if ((debugType & type) == type) {
                    if (context != null) { UnityEngine.Debug.LogError(LOG_ERROR_FLAG + message, context); return; } UnityEngine.Debug.LogError(LOG_ERROR_FLAG + message);
                }
            }
            

    }
}
